from cmath import inf
from typing import List

#单调栈
class Solution:
    def numberOfSubarrays(self, nums: List[int]) -> int:
        stack = [[inf,0]]
        ans = len(nums)
        for x in nums:
            while x > stack[-1][0]:
                stack.pop()
            if x == stack[-1][0]:
                ans += stack[-1][1]
                stack[-1][-1] += 1
            else:
                stack.append([x,1])
        return ans

if __name__ == '__main__':
    s = Solution()
    s.numberOfSubarrays([1,4,3,3,2])
